package cart

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"homepage_srv/homepageclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelLogic {
	return &CartDelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 清空购物车
func (l *CartDelLogic) CartDel(req *types.CartDelRequest) (resp *types.Response, err error) {
	add, err := l.svcCtx.HomepageGrpc.CartDel(l.ctx, &homepageclient.CartDelRequest{
		UserId: req.UserId,
	})
	if err != nil {
		return respons.Error(400, "清空购物车失败", err), err
	}
	return respons.Success(add), nil
}
